<?php

/**
 * invia actions.
 *
 * @package    cuv
 * @subpackage invia
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class inviaActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->form = new InviaForm();
  }

  public function executeSend(sfWebRequest $request)
  {
    $this->form = new InviaForm();

    if ($request->isMethod('post'))
    {
      $captcha = array(
        'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
        'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
      );

      $this->form->bind($request->getParameter('invia'), array('captcha' => $captcha));

      if ($this->form->isValid())
      {

        $message = Swift_Message::newInstance()
          ->setFrom($this->form->getValue('email_tua'))
          ->setTo($this->form->getValue('email_destinatario'))
	  ->setSubject("Per un Natale di democrazia compraunvoto.it")
          ->setBody($this->getPartial('html', array('form' => $this->form)), 'text/html')
          ->addPart($this->getPartial('text', array('form' => $this->form)));

        $this->getMailer()->send($message);
        $this->getUser()->setFlash('notice', 'message sent');
      }
    }
    $this->setTemplate('index');
  }
}
